/**
 * 时间 ： 2014-6-3 上午11:04:56
 * 作者 ： HaiTao
 * 描述 ： 当前类的描述信息
 **/
package com.laitaoo.views.home.kind
{
	import com.laitaoo.event.KindsEvent;
	import com.laitaoo.views.BaseMediator;
	
	import mx.collections.ArrayCollection;
	
	[Component]
	public class KindMediator extends BaseMediator
	{
		[Bindable]
		public var kinds:ArrayCollection;
		
		public function KindMediator()
		{
			super();
		}
		
		public function getKinds():void{
			
			var kindEvent:KindsEvent = new KindsEvent(KindsEvent.ALL_KINDS);
			eventBus.dispatchEvent(kindEvent);
		}
		[EventHandler]
		public function allKindsResultHandler(event:KindsEvent):void{
			
			kinds = event.kinds;
		}
		
		// ----------------------------------
		/**
		 * 添加分类 
		 **/
		public function insertKind(obj:Object):void{
			
			var kindEvent:KindsEvent = new KindsEvent(KindsEvent.INSERT_KIND);
			kindEvent.kindObj = obj;
			eventBus.dispatchEvent(kindEvent);
		}
		[EventHandler]
		public function insertKindResultHandler(event:KindsEvent):void{
			getKinds();
		}
		
		// ----------------------------- 编辑分类
		public function updateKind(obj:Object):void{
			
			var kindEvent:KindsEvent = new KindsEvent(KindsEvent.UPDATE_KIND);
			kindEvent.kindObj = obj;
			eventBus.dispatchEvent(kindEvent);
		}
		[EventHandler]
		public function updateKindResultHandler(event:KindsEvent):void{
			getKinds();
		}
	}
}






